# unit testing script

import unittest, pygame
import data.pointer as pointer

screenres = (800, 600)


class testPointer(unittest.TestCase):
	"""Test class for pointer module"""
	
	def setUp(self):
		self.pointer = pointer.Pointer()
		
	# Test that bouncing off a horizontal barrier gives correct direction
	def testBounceHorz(self):
		
		direction = ([10.0, -10.0])
		plane = "hor"
		self.pointer.bounce(plane)
		self.assertEqual(self.pointer.direction, direction)
	
	# Test that bouncing off a vertical barrier gives correct direction
	def testBounceVert(self):
		
		direction = ([-10.0, 10.0])
		plane = "ver"
		self.pointer.bounce(plane)
		self.assertEqual(self.pointer.direction, direction)
	
	# Test that the pointer 'starts' when started
	def testStopStartMoving(self):
		
		direction = ([0.0,0.0])
		self.assertEqual(self.pointer.stopped, False)
		
		self.pointer.stopandstart()
		
		self.assertEqual(self.pointer.stopped, True)
		self.assertEqual(self.pointer.direction, direction)
		
	# and 'stops' when stopped
	def testStopStartStopped(self):
		
		direction = ([10.0, 10.0])
		self.pointer.stopped = True
		
		self.pointer.stopandstart()
		
		self.assertEqual(self.pointer.direction, direction)
	
	# Test that the x bound of the goal is checked correctly	
	def testInRangeX(self):
	
		self.pointer.x = 85
		self.assertEqual(self.pointer.inrangex(), True)
		
		self.pointer.x = 84
		self.assertEqual(self.pointer.inrangex(), False)
		
		self.pointer.x = 740
		self.assertEqual(self.pointer.inrangex(), True)
		
		self.pointer.x = 741
		self.assertEqual(self.pointer.inrangex(), False)
		
	# Test that the y bound of the goal is checked correctly
	def testInRangeY(self):
		
		self.pointer.y = 160
		self.assertEqual(self.pointer.inrangey(), True)
		
		self.pointer.y = 159
		self.assertEqual(self.pointer.inrangey(), False)
		
		self.pointer.y = 365
		self.assertEqual(self.pointer.inrangey(), True)
		
		self.pointer.y = 366
		self.assertEqual(self.pointer.inrangey(), False)
		
	# Test that pointer location is correct after update
	def testUpdate(self):
		
		speed = self.pointer.speed
		self.pointer.update()
		x = (speed*10.0) + 300.0
		y = (speed*10.0) + 200.0
		
		self.assertEqual(self.pointer.rect.x, x)
		self.assertEqual(self.pointer.rect.y, y)
	

def suite():
	
	suite = unittest.TestSuite()
	
	suite.addTest(unittest.makeSuite(testPointer))
	return suite
	
if __name__ == '__main__':
	
	unittest.TextTestRunner(verbosity=3).run(suite())
	
	
	
